package config

import (
	"path/filepath"
	"time"

	"github.com/lab-online/pkg/jwt"
	"github.com/spf13/viper"
)

var JWT = &jwt.Config{}

func setupJWTConfig() {
	JWT.Expire = 10
	JWT.RefreshExpire = 24
	JWT.PublicKeyPath = "./public_key.pem"
	JWT.PrivateKeyPath = "./private_key.pem"
	if err := viper.UnmarshalKey("jwt", &JWT); err != nil {
		panic(err)
	}
	JWT.Expire = JWT.Expire * time.Minute
	JWT.RefreshExpire = JWT.RefreshExpire * time.Hour
	JWT.PublicKeyPath = filepath.Join(RootPath, JWT.PublicKeyPath)
	JWT.PrivateKeyPath = filepath.Join(RootPath, JWT.PrivateKeyPath)
}
